package com.spring.cloub.study.observer;

import java.util.Observable;
import java.util.Observer;

/**
 * 订观察者模式 订阅者模式
 * created by YDW
 */
public class ObserverDemo {

    public static void main(String[] args) {
        //管理器
        MyObserver myObserver= new MyObserver();
        //添加订阅者
        myObserver.addObserver(new Observer() {
            @Override
            public void update(Observable o, Object value) {
                System.out.println(value);
            }
        });
        myObserver.setChanged();
        myObserver.addObserver(new Observer() {
            @Override
            public void update(Observable o, Object value) {
                System.out.println("hhhh");
            }
        });
        //通知订阅者
        myObserver.notifyObservers("修复试运营");
    }




    public static class MyObserver extends Observable {


        public synchronized void setChanged() {
            super.setChanged();
        }
    }
}
